#version 450 compatibility






#define ParallelLightNum 3
#define PointLightNum 6
#define SpotlightNum 6



layout( location = 0 ) out vec4 fFracColor;


/******************************************************
* 上一阶段传入变量
*
*****************************************************/
in vec4 Normal;
in vec2 TCoord;


/**************************************- 灯光数据 -*****************************************
*
*/
//平行光和点光源共用属性
struct S_ParalleLight {
    vec4 m_Dir_Intensity;       //方向 强度
    vec4 m_Color_Attenuation;   //颜色 衰减
};
struct S_Spotlight {
    vec4 m_Location_Intensity;  //位置 强度
    vec4 m_Dir_Intensity;       //方向 角度
    vec4 m_Color_Attenuation;   //颜色 衰减
};


layout(std140, binding = 10) uniform _u_LightCount {
    uvec4 m_LightCount;  //x 平行光数量, y 点光源数量 , z 聚光灯数量
};
layout(std140, binding = 11) uniform _u_ParallelLight {
    S_ParalleLight m_ParalleLight[ ParallelLightNum ];
};
layout(std140, binding = 12) uniform _u_PointLight {
    S_ParalleLight m_PointLight[ PointLightNum ];
};
layout(std140, binding = 13) uniform _u_Spotlight {
    S_Spotlight m_Spotlight[ SpotlightNum ];
};




/******************************颜色参数*******************************/
layout(std140, binding = 15) uniform _u_Diffuse {
    vec4 m_DiffuseColor;
    vec4 m_HighlightColor;
    vec4 m_AmbientColor;
    uint m_TexCount;
};



layout( location = 0 ) uniform sampler2D m_TexLyer_0;
/*layout( location = 1 ) uniform sampler2D m_TexLyer_1;
layout( location = 2 ) uniform sampler2D m_TexLyer_2;
layout( location = 3 ) uniform sampler2D m_TexLyer_3;
layout( location = 4 ) uniform sampler2D m_TexLyer_4;
layout( location = 5 ) uniform sampler2D m_TexLyer_5;
layout( location = 6 ) uniform sampler2D m_TexLyer_6;
layout( location = 7 ) uniform sampler2D m_TexLyer_7;*/

#ifdef DEF_TexLayer_0

#endif

#ifdef DEF_TexLayer_0

#endif

#ifdef DEF_TexLayer_0

#endif

#ifdef DEF_TexLayer_0

#endif

#ifdef DEF_TexLayer_0

#endif

#ifdef DEF_TexLayer_0

#endif

#ifdef DEF_TexLayer_0

#endif

#ifdef DEF_TexLayer_0

#endif





void main(){

    /*************************************灯光计算区******************************************/
    uint ParalleLightCount = min(uint(ParallelLightNum), m_LightCount.x);
    uint PointLightCount = min(PointLightNum, m_LightCount.y);
    uint SpotlightCount = min(SpotlightNum, m_LightCount.z);

    vec3 diffuse = m_AmbientColor.rgb;
    vec3 parameterDiffuse = m_DiffuseColor.rgb*m_DiffuseColor.a + m_HighlightColor.rgb*m_HighlightColor.a;


    if(m_TexCount<=1){
        diffuse = texture(m_TexLyer_0, TCoord*1000.0).rgb;
        //diffuse.xy = TCoord;
    }


    vec3 LightPos = vec3(0, 0, 0);
    //计算平行光照
    for(int i=0; i<ParalleLightCount; ++i){
        LightPos = m_ParalleLight[i].m_Dir_Intensity.xyz;
        //diffuse += parameterDiffuse * max(0.0, dot(normalize(LightPos), normalize(Normal).xyz)) * 0.1;
    }

    for(int i=0; i<PointLightCount; ++i){
    }

    for(int i=0; i<SpotlightCount; ++i){
    }


    fFracColor = vec4(diffuse, 1.0);

}



